package lab3_2;

public class SubstractOperation extends BinaryOperation {
    
    public SubstractOperation() {
        super();
        this.operator = '-';
    }
    
    public SubstractOperation(int left, int right) {
        super(left, right, '-');
    }
    
    @Override
    public int calculate(int left, int right) {
        return left - right;
    }
    
    @Override
    public boolean checkingCalculation(int left, int right) {
        int result = left - right;
        return result >= LOWER && result <= UPPER;
    }
    
    // 生成满足条件的减法算式
    public static SubstractOperation generateSubstractOperation() {
        int left, right;
        do {
            left = random.nextInt(UPPER + 1);
            right = random.nextInt(UPPER + 1);
        } while (!new SubstractOperation().checkingCalculation(left, right));
        
        return new SubstractOperation(left, right);
    }
}